/**************************************************************
 * @file     bsp_led.c
 * @brief    ??????????led
 * @author   Ruilist
 * @date     2025-07-26
 * @version  V1.0.0
 * @copyright Copyright (c) 2025
 *
 * @note     1 tab = 4 space
 *
 * @par ??:
 * - V1.0.0 2025-07-26 Ruilist
 *   ??????????led
 **************************************************************/

#include "bsp_led.h"

osThreadId_t         led_TaskHandle;
const osThreadAttr_t led_Task_attributes = {
    .name       = "led_Task",
    .stack_size = 128 * 4,
    .priority   = (osPriority_t)osPriorityNormal,
};

QueueHandle_t led_queue;

/**
 * @brief   ??led??
 *
 * @param   led_operation    ??led????
 *
 * @return  ????? led_status_t
 *
 */
led_status_t led_on_off( led_operation_t led_operation )
{
    led_status_t ret = LED_OK;

    if ( LED_ON == led_operation )
    {
        HAL_GPIO_WritePin( LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET );  // led on
    }
    if ( LED_OFF == led_operation )
    {
        HAL_GPIO_WritePin( LED_GPIO_Port, LED_Pin, GPIO_PIN_SET );  // led off
    }
    if ( LED_TOGGLE == led_operation )  // led toggle
    {
        HAL_GPIO_TogglePin( LED_GPIO_Port, LED_Pin );
    }
}

/**
 * @brief   led??
 *
 * @param   *argument    ??????
 *
 * @return  ?
 *
 */
void led_task_func( void *argument )
{
    printf( "start led_task_func\r\n" );

    led_status_t    led_ret   = LED_OK;
    led_operation_t led_value = LED_ON;
    led_queue                 = xQueueCreate( 10, sizeof( led_operation_t ) );
    if ( NULL == led_queue )
    {
        printf( "led_queue created failed \r\n" );
    }
    else
    {
        printf( "led_queue created successfully \r\n" );
    }
    for ( ;; )
    {
        if ( led_queue != 0 )
        {
            if ( xQueueReceive( led_queue, &( led_value ), (TickType_t)100 ) )
            {
                printf( "received led_queue value = [%d]", led_value );
                led_on_off( led_value );
            }
        }
        osDelay( 100 );
    }
}
